package com.chaoyong.higo.base;

import java.util.ArrayList;
import java.util.List;

import com.chaoyong.higo.utils.EmptyUtil;

import android.content.Context;
import android.view.LayoutInflater;



public abstract class BaseAdapter<T> extends android.widget.BaseAdapter {

    protected List<T> mList;
    protected LayoutInflater mInflater;
    protected Context mContext;

    public BaseAdapter(Context context) {
        mList = new ArrayList<T>();
        mInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mContext = context;
    }

    public void clearData() {
        mList.clear();
    }

    public void addAllData(List<T> list) {
        if (!EmptyUtil.isEmpty(list)) {
            mList.addAll(list);
        }
    }

    public void setList(List<T> list) {
        if (!EmptyUtil.isEmpty(list)) {
            mList = list;
            this.notifyDataSetChanged();
        }
    }

    public void addAllDataAndNorify(List<T> list) {
        this.addAllData(list);
        this.notifyDataSetChanged();
    }
    
    public List<T> getData() {
        return mList;
    }

    public void refreshAdapter(List<T> list) {
        mList.clear();
        if (!EmptyUtil.isEmpty(list)) {
            mList.addAll(list);
        }
        this.notifyDataSetChanged();
    }

    /**
     * 根据实际情况覆盖该方法
     */
    @Override
    public int getCount() {
        if (EmptyUtil.isEmpty(mList))
            return 0;
        return mList.size();
    }

    /**
     * 根据实际情况覆盖该方法
     */
    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

}
